<template>
	<view class="container">
		<view class="empty_top">

		</view>
		<view class="logo">
			<image src="../../static/image/logo.jpg" mode="aspectFit"></image>
		</view>

		<view class="ipt">
			<view class="account">
				<input type="number" placeholder="请输入您的账号" placeholder-style="color: #b3b3b3" v-model="mobile" />
			</view>
			<view class="password">
				<input type="password" placeholder="请输入您的密码" placeholder-style="color: #b3b3b3" v-model="password" />
			</view>
			<view class="to">
				<text class="forget" @click="forget">忘记密码?</text>
				<text class="register" @click="register">立即注册</text>
			</view>
		</view>

		<view class="submit" @click="login">
			<text>登录</text>
		</view>
	</view>
</template>

<script>
	import {
		login
	} from '../../api/api.js'
	export default {
		data() {
			return {
				mobile: '',
				password: ''
			}
		},
		onLoad() {
			// let token = uni.getStorageSync('token')
			// if (token) {
			// 	uni.navigateTo({
			// 		url: '/pages/index/index'
			// 	})
			// }
		},
		methods: {
			register() {
				uni.navigateTo({
					url: '/pages/login/register'
				})
			},
			forget() {
				uni.navigateTo({
					url: '/pages/login/forget'
				})
			},
			login() {
				login({
					mobile: this.mobile,
					password: this.password
				}).then(res => {
					if (res.data.userinfo.is_agent == 1) {
						uni.setStorageSync('token', res.data.userinfo.token);
						uni.setStorageSync('user_id',res.data.userinfo.id)
						uni.reLaunch({
							url: '/pages/agent/index'
						})
					}else{
						uni.showModal({
							title: '提示',
							content: '暂无权限',
							showCancel: false,
							success: function(res) {
								// uni.reLaunch({
								// 	url: '/pages/login/login'
								// })
							}
						})
					}
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.container {
		width: 100%;
		height: 100%;
		background-color: #ffffff;

		.empty_top {
			height: 10%;
		}

		.logo {
			width: 150upx;
			height: 150upx;
			border-radius: 50%;
			// border: 1upx solid #ededed;
			margin: 0 auto;
			line-height: 150upx;
			text-align: center;
			color: #adadad;
			image{
				width: 100%;
				height: 100%;
			}
		}

		.ipt {
			margin-top: 5%;
		}

		.account,
		.password {
			width: 90%;
			height: 90upx;
			margin: 0 5% 30upx;
			border: 1upx solid #f2f2f2;
			border-radius: 50upx;

			input {
				width: calc(100% - 30upx);
				height: 100%;
				margin-left: 30upx;
				// text-indent: 30upx;
			}
		}

		.to {
			width: calc(90% - 60upx);
			margin: 0 auto;
			color: #b3b3b3;
			display: flex;
			justify-content: space-between;

			.register {
				color: #5ec2ff;
			}
		}

		.submit {
			width: 90%;
			height: 90upx;
			margin: 30upx auto;
			background-color: #3eb9ff;
			border-radius: 50upx;
			color: #FFFFFF;
			line-height: 90upx;
			text-align: center;
		}


	}
</style>
